package ks.app.smartDic;

import net.daum.mobilead.MobileAdView;

import com.google.ads.*;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.Toast;

public class smartDic extends Activity implements OnClickListener {

	MobileAdView adViewAdam;
	MultipleAd mAd;
	Button searchBtn;

	EditText editText;

	ImageView btnWord;
	ImageView btnPreference;
	ImageView btnEngToKorean;
	ImageView btnKorean;
	ImageView btnKoreanToEng;
	ImageView btnEngToEng;

	//AdView adView;
	AdRequest request;

	GoogleAnalyticsTracker tracker;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		btnEngToKorean = (ImageView) findViewById(R.id.btnEngToKorean);
		btnEngToKorean.setOnClickListener(this);

		btnKorean = (ImageView) findViewById(R.id.btnKorean);
		btnKorean.setOnClickListener(this);

		btnKoreanToEng = (ImageView) findViewById(R.id.btnKoreanToEng);
		btnKoreanToEng.setOnClickListener(this);

		btnEngToEng = (ImageView) findViewById(R.id.BtnEngToEng);
		btnEngToEng.setOnClickListener(this);

		btnWord = (ImageView) findViewById(R.id.btnWord);
		btnWord.setOnClickListener(this);
		btnPreference = (ImageView) findViewById(R.id.btnPreference);
		btnPreference.setOnClickListener(this);

		adViewAdam = (MobileAdView) findViewById(R.id.adviewAdam);

		mAd = new MultipleAd(getApplicationContext(), adViewAdam,
				"308Z0CT12dd46458a1");
		mAd.displayAd();

		// Create the adView
		/*
		 * adView = new AdView(this, AdSize.BANNER,
		 * getString(R.string.ADMOB_PUBLISHER_ID)); RelativeLayout layout =
		 * (RelativeLayout) findViewById(R.id.main);
		 * 
		 * RelativeLayout.LayoutParams layoutParams = new
		 * RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT,
		 * LayoutParams.WRAP_CONTENT);
		 * layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
		 * RelativeLayout.TRUE); layout.addView(adView, layoutParams);
		 * adView.loadAd(new AdRequest());
		 */

		// 업데이트 체크
		UpdateNotifier un = new UpdateNotifier(this);
		un.execute();

		tracker = GoogleAnalyticsTracker.getInstance();
		tracker.start("UA-22873894-1", 20, this);
		tracker.trackPageView("/main");
		tracker.setProductVersion("ver", String.valueOf(un.getVersionCode()));
		tracker.setCustomVar(1, "version", String.valueOf(un.getVersionCode()),
				1);
		tracker.dispatch();

	}

	public void onClick(View v) {

		Intent intentToSearchView = new Intent(getApplicationContext(),
				SearchView.class);

		if (v == btnEngToKorean) {

			intentToSearchView.putExtra(getString(R.string.SORT_OF_DICTIONARY),
					getString(R.string.ENG_TO_KOREAN));
		} else if (v == btnKorean) {

			intentToSearchView.putExtra(getString(R.string.SORT_OF_DICTIONARY),
					getString(R.string.KOREAN_TO_KOREAN));
		} else if (v == btnKoreanToEng) {

			intentToSearchView.putExtra(getString(R.string.SORT_OF_DICTIONARY),
					getString(R.string.KOREAN_TO_ENG));
		} else if (v == btnEngToEng) {

			intentToSearchView.putExtra(getString(R.string.SORT_OF_DICTIONARY),
					getString(R.string.ENG_TO_ENG));
		} else if (v == btnWord) {

			Toast.makeText(getApplicationContext(), "다음 버전에서 지원됩니다.",
					Toast.LENGTH_SHORT).show();
			return;
		} else if (v == btnPreference) {

			intentToSearchView = new Intent(this, PreferenceUI.class);
		}

		startActivity(intentToSearchView);

	}

	protected void onResume() {

		super.onResume();

		mAd.displayAd();
		//adView.loadAd(request);

	}

	@Override
	public void onDestroy() {
		//adView.destroy();
		super.onDestroy();
	}

}